/* This program produces the parts of Table B.3 that use household survey data 
- The table has to be assembled manually */

***** Set directories 
local dir_raw 		"~/Dropbox/Retirement gaming/raw"
local dir_clean 	"~/Dropbox/Retirement gaming/clean"
local dir_output 	"~/Dropbox/Retirement gaming/output/dataverse"


use "`dir_clean'/ech_clean.dta", clear

local listcontrols = " i.t i.fsize i.ciiu2  i.year#i.fsize i.year#i.ciiu2   " 

cap drop sample_self_empl
reghdfe W age_centered if self_empl==1 [aw=weight], absorb(`listcontrols') vce(robust)
g sample_self_empl=e(sample)
reghdfe W age_centered if (empl==1 & small==1 ) [aw=weight], absorb(`listcontrols') vce(robust)
g sample_emplsmall=e(sample)
reghdfe W age_centered if (empl==1 & small==0 ) [aw=weight], absorb(`listcontrols') vce(robust)
g sample_empllarge=e(sample)


* SELF-EMPLOYED 
estimates clear
eststo: quietly estpost summarize W if sample_self==1 & age_centered<0 [aw=weight], casewise esample
eststo: quietly estpost summarize W if sample_self==1 & age_centered>=0 & age_centered<4 [aw=weight], casewise esample
eststo: quietly estpost summarize W if sample_self==1 & age_centered>=4 & age_centered<. [aw=weight], casewise esample
esttab using "`dir_output'/tableB3_survey.tex", replace ///
	cells("mean(fmt(2))")  nostar nonote label nonumber nodepvar ///
	mtitles("Age 45-49" "Age 50-53" "Age 54-57") ///
	style(tex) f nogaps noobs		
* SMALL FIRM EMPLOYEES 
estimates clear
foreach s in 0 {
	eststo: quietly estpost summarize W if sample_emplsmall==1 & age_centered<0 [aw=weight], casewise esample
	eststo: quietly estpost summarize W if sample_emplsmall==1 & age_centered>=0 & age_centered<4 [aw=weight], casewise esample
	eststo: quietly estpost summarize W if sample_emplsmall==1 & age_centered>=4 & age_centered<. [aw=weight], casewise esample
}
esttab using "`dir_output'/tableB3_survey.tex", append ///
	cells("mean(fmt(2))")  nostar nonote label nonumber nodepvar ///
	nomtitles ///
	style(tex) f nogaps noobs		
* LARGE FIRM EMPLOYEES 
estimates clear
foreach s in 1 {
	eststo: quietly estpost summarize W if sample_empllarge==1 & age_centered<0 [aw=weight], casewise esample
	eststo: quietly estpost summarize W if sample_empllarge==1 & age_centered>=0 & age_centered<4 [aw=weight], casewise esample
	eststo: quietly estpost summarize W if sample_empllarge==1 & age_centered>=4 & age_centered<. [aw=weight], casewise esample
}
esttab using "`dir_output'/tableB3_survey.tex", append ///
	cells("mean(fmt(2))")  nostar nonote label nonumber nodepvar ///
	nomtitles ///
	style(tex) f nogaps noobs	
	
